﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SimpleLibraryClasses;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace SimpleLibraryWebForm
{
    public partial class XMLWizard : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnInitializeLibrary_Click(object sender, EventArgs e)
        {
            Library lib = new Library();
            lib.LibraryName = "Sample Library";
            CreateMembers(lib);
            CreateBooks(lib);
            CreateDevices(lib);
            lib.SaveLibrary(LibraryFileHandler.GetLibraryFileName());
        }

        protected void CreateMembers(Library lib)
        {
            lib.AddMember(new Member("1", "Jason", "Schatz"));
            lib.AddMember(new Member("2", "Devin", "Serink"));
            lib.AddMember(new Member("3", "Bill", "Penne"));
            lib.AddMember(new Member("4", "Anthony", "Cumia"));
            lib.AddMember(new Member("5", "Mike", "Myers"));
            lib.AddMember(new Member("6", "Norm", "MacDonald"));
            lib.AddMember(new Member("7", "Tracy", "Morgan"));
            lib.AddMember(new Member("8", "Bill", "Burr"));
            lib.AddMember(new Member("9", "James", "Norton"));
            lib.AddMember(new Member("10", "Greg", "Hughes"));
        }

        protected void CreateBooks(Library lib)
        {
            lib.AddItem(MakeBook("The Hobbit", "J.R.R. Tolkien", "10000", "Houghton Mifflin", new DateTime(1937, 1, 1)));
            lib.AddItem(MakeBook("Fellowship of the Ring", "J.R.R. Tolkien", "10001", "Houghton Mifflin", new DateTime(1954, 1, 1)));
            lib.AddItem(MakeBook("The Two Towers", "J.R.R. Tolkien", "10002", "Houghton Mifflin", new DateTime(1956, 1, 1)));
            lib.AddItem(MakeBook("The Return Of the King", "J.R.R. Tolkien", "10003", "Houghton Mifflin", new DateTime(1954, 1, 1)));
            lib.AddItem(MakeBook("Pebble In The Sky", "Isaac Asimov", "10004", "Doubleday", new DateTime(1950, 1, 1)));
            lib.AddItem(MakeBook("The Stars, Like Dust", "Isaac Asimov", "10005", "Doubleday", new DateTime(1951, 1, 1)));
            lib.AddItem(MakeBook("Foundation", "Isaac Asimov", "10006", "Doubleday", new DateTime(1951, 1, 1)));
            lib.AddItem(MakeBook("Foundation and Empire", "Isaac Asimov", "10007", "Gnome Press", new DateTime(1952, 1, 1)));
            lib.AddItem(MakeBook("Second Foundation ", "Isaac Asimov", "10008", "Gnome Press", new DateTime(1953, 1, 1)));
            lib.AddItem(MakeBook("The Caves of Steel", "Isaac Asimov", "10009", "Doubleday", new DateTime(1954, 1, 1)));
            lib.AddItem(MakeBook("Fantastic Voyage", "Isaac Asimov", "10010", "Doubleday", new DateTime(1966, 1, 1)));
            lib.AddItem(MakeBook("The Gods Themselves", "Isaac Asimov", "10011", "Doubleday", new DateTime(1972, 1, 1)));
            lib.AddItem(MakeBook("Foundation's Edge", "Isaac Asimov", "10012", "Doubleday", new DateTime(1982, 1, 1)));
            lib.AddItem(MakeBook("The Robots of Dawn", "Isaac Asimov", "10013", "Doubleday", new DateTime(1983, 1, 1)));
            lib.AddItem(MakeBook("Robots and Empire", "Isaac Asimov", "10014", "Doubleday", new DateTime(1985, 1, 1)));
            lib.AddItem(MakeBook("Foundation and Earth", "Isaac Asimov", "10015", "Doubleday", new DateTime(1986, 1, 1)));
            lib.AddItem(MakeBook("Prelude to Foundation", "Isaac Asimov", "10019", "Doubleday", new DateTime(1988, 1, 1)));
            lib.AddItem(MakeBook("Nemesis", "Isaac Asimov", "10017", "Doubleday", new DateTime(1989, 1, 1)));
            lib.AddItem(MakeBook("Nightfall", "Isaac Asimov", "10018", "Doubleday", new DateTime(1990, 1, 1)));
            lib.AddItem(MakeBook("Forward the Foundation", "Isaac Asimov", "10019", "Doubleday", new DateTime(1993, 1, 1)));
            lib.AddItem(MakeBook("The Positronic Man", "Isaac Asimov", "10020", "Doubleday", new DateTime(1993, 1, 1)));
        }

        protected void CreateDevices(Library lib)
        {
            lib.AddItem(MakeDevice("Macbook Pro", "M2A2005", "XC19FBHC1887-5", DeviceType.Laptop));
            lib.AddItem(MakeDevice("Macbook Pro", "M2A2005", "XC20FBHC1445-6", DeviceType.Laptop));
            lib.AddItem(MakeDevice("IBM Thinkpad X220", "X220-A9948", "FBH220-18273", DeviceType.Laptop));
            lib.AddItem(MakeDevice("Lenovo R4200", "R4200A-K99886", "RDH443J009283", DeviceType.Laptop));
            lib.AddItem(MakeDevice("Dell 2208WFP", "320-6106887", "49488837282", DeviceType.Monitor));
            lib.AddItem(MakeDevice("iPod Touch", "IPOD-4456", "4958277376", DeviceType.Peripheral));
            lib.AddItem(MakeDevice("Panasonic AE700", "AE700D-5447", "498A847FB74E", DeviceType.Projector));
            lib.AddItem(MakeDevice("Samsung 55\" TV", "UN55B8000", "B8000-2877F84A", DeviceType.TV));
        }

        private Device MakeDevice(String name, String model, String serial, DeviceType type)
        {
            Device device = new Device();
            device.ItemCode = serial;
            device.Serial = serial;
            device.DeviceName = name;
            device.Model = model;
            device.DeviceType = type;
            return device;
        }

        private Book MakeBook(String title, String author, String isbn, String publisher, DateTime publishDate)
        {
            Book book = new Book();
            book.Title = title;
            book.Author = author;
            book.ItemCode = isbn;
            book.ISBN = isbn;
            book.Publisher = publisher;
            book.PublishDate = publishDate;
            return book;
        }
    }
}
